//
//  CategoryDataSource.m
//  freeLance
//
//  Created by Igor Karpenko on 3/27/13.
//  Copyright (c) 2013 Mozi Development. All rights reserved.
//

#import "CollectionHeaderView.h"
#import "CategoryViewCell.h"
#import "CoreDataRoutines.h"
#import "CDCategories.h"

#import "CategoryDataSource.h"

@implementation CategoryDataSource


#pragma mark - Action methods

-(void) fetchItemsWithCategoryId:(NSNumber *)categoryId {
	CoreDataRoutines *coreDataRoutines = [CoreDataRoutines sharedInstance];
	_items = [[coreDataRoutines categoryWithIdent:categoryId].collections allObjects];
}


#pragma mark - Delegated methods

-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
	return _items.count;
}


-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView
				  cellForItemAtIndexPath:(NSIndexPath *)indexPath {
	CategoryViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:categoryCellIdentifier forIndexPath:indexPath];
	cell.collection = nil;
	cell.collection = _items[indexPath.row];

	return cell;
}


-(UICollectionReusableView *) collectionView: (UICollectionView *)collectionView
		   viewForSupplementaryElementOfKind:(NSString *)kind
								 atIndexPath:(NSIndexPath *)indexPath {
    CollectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
																		  withReuseIdentifier:collectionHeaderIdentifier forIndexPath:indexPath];
	
    return headerView;
}


@end
